﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace StoneStorage
{
    public class Filter
    {
        public int? StoneId
        {
            get;
            set;
        }

        public int? ProducerId
        {
            get;
            set;
        }

        public int? Length
        {
            get;
            set;
        }

        public int? Width
        {
            get;
            set;
        }

        public int? Height
        {
            get;
            set;
        }

        public string CreateFilterString()
        {
            FilterHelper filterHelper0 = new FilterHelper(StoneId, "StoneId");
            FilterHelper filterHelper1 = new FilterHelper(ProducerId, "ProducerId");
            FilterHelper filterHelper2 = new FilterHelper(Length, "StoneLength");
            FilterHelper filterHelper3 = new FilterHelper(Width, "StoneWidth");
            FilterHelper filterHelper4 = new FilterHelper(Height, "StoneHeight");
            
            List<FilterHelper> filterHelperList = new List<FilterHelper>();
            filterHelperList.Add(filterHelper0);
            filterHelperList.Add(filterHelper1);
            filterHelperList.Add(filterHelper2);
            filterHelperList.Add(filterHelper3);
            filterHelperList.Add(filterHelper4);

            var res = filterHelperList.Where(f => f.FilterPropetyValue != null);
            
            string filterString = "";
            
            foreach(var f in res)
            {
                if (filterString != "")
                {
                    filterString = filterString + " and ";
                }

                filterString = filterString + f.FilterPropetyName + " = " + f.FilterPropetyValue;
            }

            return filterString;
        }
        
        public void FilterZiroOut()
        {
            StoneId = null;
            ProducerId = null;
            Length = null;
            Width = null;
            Height = null;
        }
    }
}
